package com.qzimp.fujiancuo.controller;

import com.qzimp.fujiancuo.entity.Album;
import com.qzimp.fujiancuo.entity.Enterprise;
import com.qzimp.fujiancuo.entity.dto.CuoDto;
import com.qzimp.fujiancuo.entity.dto.CuoEnterpriseDto;
import com.qzimp.fujiancuo.entity.dto.ImgCategoryDto;
import com.qzimp.fujiancuo.entity.liouwenEmail;
import com.qzimp.fujiancuo.entity.vo.ResultCode;
import com.qzimp.fujiancuo.entity.vo.ResultVo;
import com.qzimp.fujiancuo.exceptions.ApiException;
import com.qzimp.fujiancuo.mapper.EnterpriseMapper;
import com.qzimp.fujiancuo.mapper.ImageCategoryMapper;
import com.qzimp.fujiancuo.service.EnterpriseService;
import com.qzimp.fujiancuo.service.ImageCategoryService;
import com.qzimp.fujiancuo.service.liouwenEmailService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.io.Serializable;
import java.util.List;


@RestController
@RequestMapping("/auth")
public class LiouwenController {
    @Resource
    EnterpriseMapper enterpriseMapper;
    @Resource
    ImageCategoryMapper imageCategoryMapper;
    @Autowired
    private liouwenEmailService emailService;
    @GetMapping("/sendValidateCode")
    @ApiOperation("邮件模块")
    public ResultVo sendValidateCode(String mail){
        String[] emails={mail};
        if(StringUtils.isEmpty(mail)){
            throw new ApiException(ResultCode.CUSTOM_ERROR,"邮件接收者不能为空");
        }
        try {
            liouwenEmail email=new liouwenEmail();
            email.setUser(emails);
            email.setSubject("发送邮件");
            email.setContent("这是一封邮件");
            emailService.sendMail(email);
            return new ResultVo(ResultCode.SUCCESS);
        }
        catch (Exception e){
            throw new ApiException(ResultCode.CUSTOM_ERROR,"邮件发送失败");
        }
    }

    @GetMapping("/getEnterprisebyName")
    @ApiOperation(value = "根据厝的名字获取相关企业", notes = "根据厝的名字获取相关企业")
    public ResultVo getEnterprisebyName(String name) {
        List<CuoEnterpriseDto> enterprisebyName = enterpriseMapper.getEnterprisebyId(name);
        return new ResultVo(enterprisebyName);
    }

    @GetMapping("/getAblumbyName")
    @ApiOperation(value = "通过图片分类查询图片", notes = "通过图片分类查询图片")
    public ResultVo getAblumbyName(String name) {
        List<ImgCategoryDto> ablumbyName = imageCategoryMapper.getAblumbyName(name);
        return new ResultVo(ablumbyName);
    }
}
